import Utiles.Chain;

public class Main_092 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		int count = 0;
		for (int i = 2; i < 10000000; i++) {

			int ak = i;
			//System.out.print(ak);
			while (ak != 1 && ak != 89) {
				//System.out.print(" -> ");
				ak = Chain.nextChain(ak);
				//System.out.print(ak);
			}
			//System.out.print("\n");
			if (ak == 89) {
				++count;
			}
		}
		System.out.println(count);
	}

}
